Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pointer events affect focus #822

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Make pointer events affect focus #822

merged 4 commits into from
Jan 14, 2025

Conversation

PoignardAzur
Copy link
Contributor

@PoignardAzur PoignardAzur commented Jan 14, 2025

Clear the focus when user clicks outside of the focused widget
Add most_recently_clicked_widget value, so that clicking influences which widget will be focused by future Tab events.

@PoignardAzur PoignardAzur changed the title Makes pointer events affect focus Make pointer events affect focus Jan 14, 2025
if !root
.widget_arena
.states
.get_id_path(target_widget_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to be in what context a possibly focusable widget could be nested inside another possibly focusable widget (that is, why this isn't just target_widget_id != focused_widget)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree, but I don't want to make it a hard rule either.

@@ -616,7 +621,7 @@ impl RenderRoot {
}

pub(crate) fn widget_from_focus_chain(&mut self, forward: bool) -> Option<WidgetId> {
let focused_widget = self.global_state.focused_widget;
let focused_widget = self.global_state.ghost_focus;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be:

Suggested change
let focused_widget = self.global_state.ghost_focus;
let focused_widget = self.global_state.focused_widget.or(self.global_state.ghost_focus);

That is, if there is an actual currently focused widget, we should start from that for tab-focusing and the like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, fair enough. I would let me remove a lot of code that tries to keep ghost focus and regular focus synchronized.

masonry/src/passes/event.rs Outdated Show resolved Hide resolved
I ain't afraid of no ghost.
@@ -74,6 +74,7 @@ pub(crate) struct RenderRootState {
pub(crate) focused_widget: Option<WidgetId>,
pub(crate) focused_path: Vec<WidgetId>,
pub(crate) next_focused_widget: Option<WidgetId>,
pub(crate) most_recently_clicked_widget: Option<WidgetId>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth having just a sprinkling of documentation/explanation here (the same could be said about most of these fields, but this one is a bit non-obvious)

@PoignardAzur PoignardAzur added this pull request to the merge queue Jan 14, 2025
Merged via the queue into main with commit d49b06a Jan 14, 2025
17 checks passed
@PoignardAzur PoignardAzur deleted the improve_focus branch January 14, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants